const path = require('path'),
    HtmlWebpackPlugin = require('html-webpack-plugin'),
    MiniCssExtractPlugin = require("mini-css-extract-plugin"),
    webpack = require('webpack'),
    CleanWebpackPlugin = require('clean-webpack-plugin');

module.exports = (options) => (console.log(options),{
    mode: 'development',
    entry: path.resolve(__dirname, 'src/index.js'),
    output: {
        path: path.resolve(__dirname, 'dist')
    },
    plugins: [
        new HtmlWebpackPlugin({
            title: 'webpack测试配置文件',
            template: path.join(__dirname, 'src/index.html'),
            // hash: true
        }),
        new MiniCssExtractPlugin({
            // Options similar to the same options in webpackOptions.output
            // both options are optional
            filename: "[name].css",
            chunkFilename: "[id].css"
        }),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery'
        }),
        new CleanWebpackPlugin(['dist'])
    ],
    module: {
        rules: [{
                test: /\.less$/,
                loader: [
                    MiniCssExtractPlugin.loader,
                    'css-loader',
                    'less-loader',
                    'postcss-loader'
                ]
            },
            {
                test: /\.css$/,
                // use: ['style-loader', 'css-loader']
                loader:[MiniCssExtractPlugin.loader,'css-loader']
            },
            {
                test: /\.(png)|(jpg)|(gif)|(woff)|(svg)|(eot)|(ttf)$/,
                use: [{
                    loader: "url-loader",
                    options: {
                        limit: 50000, //小于50K的 都打包
                        name: "[hash:8].[name].[ext]"
                    }
                }]
            }
        ]
    }

});